package com.hea7en.demo.controller;

import com.hea7en.demo.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

/**
 * @author: hea7en
 * @Date: 2024/8/19 5:29 PM
 * @Description: 控制层
 */
@Controller
public class StudentController {

    /**
     * 测试模版页面
     * @param model
     * @return
     */
    @GetMapping("/demo")
    public String testPage(Model model) {
        model.addAttribute("name", "hea7en");

        Student stu = new Student();
        stu.setName("heaven");
        stu.setAge(18);
        model.addAttribute("stu", stu);

        return "test_page";
    }

    @GetMapping("/list")
    public String testListMap(Model model){
        Student stu1 = new Student("zhangsan", 20, null, 100F);
        Student stu2 = new Student("lisi", 23, null, 200F);

        // List
        ArrayList<Student> stuList = new ArrayList<>(12);
        stuList.add(stu1);
        stuList.add(stu2);
        model.addAttribute("stuList", stuList);

        // Map
        HashMap<String, Object> stuMap = new HashMap<>(12);
        stuMap.put("stu1", stu1);
        stuMap.put("stu2", stu2);
        model.addAttribute("stuMap", stuMap);

        // 添加日期
        Date date = new Date();
        model.addAttribute("today", date);

        //  添加数值
        model.addAttribute("point", 102920122);

        return "test_list";
    }
}
